package golf.stockdata.framework.batch.dataobject;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;

public class JobStepData implements Serializable{

	/**
	 * 
	 */
	private static final long serialVersionUID = 6700226386090930634L;
	
	private String name;
	private String type;
	private String className;
	private String command;

    private Map<String, String> propertyMap = new HashMap<String, String>();
    
    @XmlElementWrapper(name = "parameters")
    @XmlElement(name = "parameter")  
    public MapEntry[] getMap() {  
        List<MapEntry> list = new ArrayList<MapEntry>();  
        for (Entry<String, String> entry : propertyMap.entrySet()) {
            MapEntry mapEntry =new MapEntry();  
            mapEntry.name = entry.getKey();  
            mapEntry.value = entry.getValue();  
            list.add(mapEntry);  
        }  
        return list.toArray(new MapEntry[list.size()]);  
    }
    
    public void putParameter(String key, String value){
    	propertyMap.put(key, value);
    }
    
    public String getParameter(String key){
    	return propertyMap.get(key);
    }
    
    public Map<String, String> getParameters(){
    	return propertyMap;
    }
      
    public void setMap(MapEntry[] arr) {  
    	int count = 0;
        for(MapEntry entry : arr) {
        	if(entry.name != null){
                this.propertyMap.put(entry.name, entry.value);  
        	}else{
        		this.propertyMap.put(Integer.toString(count), entry.value);
        	}
        	count++;
        }  
    }  
  
	
	@XmlElement(name = "name")
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}

	@XmlAttribute(name = "type")
	public String getType() {
		return type;
	}
	public void setType(String type) {
		this.type = type;
	}
	
	@XmlAttribute(name = "class")
	public String getClassName() {
		return className;
	}
	public void setClassName(String className) {
		this.className = className;
	}
	
	@XmlAttribute(name = "cmd")
	public String getCommand() {
		return command;
	}
	public void setCommand(String command) {
		this.command = command;
	}
	
	

}
